package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.AnimalConservationLocation;
import com.fsnbigdata.domain.AnimalConservation;
import com.fsnbigdata.domain.QAnimalConservationLocation;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = AnimalConservationLocationRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = AnimalConservationLocationRepositoryCustom.class)
@Transactional(readOnly = true)
public class AnimalConservationLocationRepositoryImpl extends QueryDslRepositorySupportExt<AnimalConservationLocation> implements AnimalConservationLocationRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    AnimalConservationLocationRepositoryImpl() {
        super(AnimalConservationLocation.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ANIMAL_CONSERVATION = "animalConservation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CONSERVATION_START_DATE = "conservationStartDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CONSERVATION_RESULT = "conservationResult";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PRESERVE_LOCATION = "preserveLocation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String QUANTITY = "quantity";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String RECORDER = "recorder";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CONSERVATION_WAY = "conservationWay";

    /**
     * TODO Auto-generated method documentation
     *
     * @param animalConservation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<AnimalConservationLocation> findByAnimalConservation(AnimalConservation animalConservation, GlobalSearch globalSearch, Pageable pageable) {
        QAnimalConservationLocation animalConservationLocation = QAnimalConservationLocation.animalConservationLocation;
        JPQLQuery<AnimalConservationLocation> query = from(animalConservationLocation);
        Assert.notNull(animalConservation, "animalConservation is required");
        query.where(animalConservationLocation.animalConservation.eq(animalConservation));
        Path<?>[] paths = new Path<?>[] { animalConservationLocation.animalConservation, animalConservationLocation.preserveLocation, animalConservationLocation.quantity, animalConservationLocation.conservationWay, animalConservationLocation.conservationStartDate, animalConservationLocation.conservationResult, animalConservationLocation.recorder };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(ANIMAL_CONSERVATION, animalConservationLocation.animalConservation).map(PRESERVE_LOCATION, animalConservationLocation.preserveLocation).map(QUANTITY, animalConservationLocation.quantity).map(CONSERVATION_WAY, animalConservationLocation.conservationWay).map(CONSERVATION_START_DATE, animalConservationLocation.conservationStartDate).map(CONSERVATION_RESULT, animalConservationLocation.conservationResult).map(RECORDER, animalConservationLocation.recorder);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, animalConservationLocation);
    }
}
